package domain.util;

import java.util.List;
import java.util.Vector;

public class MarcLine {

	private String field;
	private String indicator1, indicator2;
	private List<Subfield> subfields;
	
	public MarcLine(String field) {
		this.field = field;
		this.indicator1 = this.indicator2 = " ";
		this.subfields = new Vector<Subfield>();
	}

	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}

	public String getIndicator1() {
		return indicator1;
	}

	public void setIndicator1(String indicator1) {
		this.indicator1 = indicator1;
	}

	public String getIndicator2() {
		return indicator2;
	}

	public void setIndicator2(String indicator2) {
		this.indicator2 = indicator2;
	}

	public List<Subfield> getSubfields() {
		return subfields;
	}

	public void setSubfields(List<Subfield> subfields) {
		this.subfields = subfields;
	}

	public void alter(String typeField, String subField, String value) {
		if (typeField.equals("indicator1"))
			setIndicator1(value);
		else if (typeField.equals("indicator2"))
			setIndicator2(value);
		else {
			subfields.add(new Subfield(subField, value));
		}
	}
	
	@Override
	public String toString() {
		String result = field;
		
		result += " " + indicator1 + indicator2;
		
		for (Subfield s : subfields)
			result += " " + s.toString();
		
		return result;
	}
}
